package scenic.toolkit;

import java.util.Vector;

import scenic.Graphics;
import scenic.toolkit.db.SyncVector;

public class TextView extends ComponentView {
	private ParagraphVector paragraphs;
	
	private class ParagraphVector extends SyncVector<ParagraphView> {
		public ParagraphVector() {
			super(getModel().getParagraphs());
		}
		
		@Override
		public ParagraphView createObject(int index, Object sourceNode) {
			ParagraphView p = new ParagraphView((ParagraphModel)sourceNode, TextView.this);
			
			invalidate();
			return p;
		}

		@Override
		public void removeObject(int index, Object object) {
			invalidate();
		}		
	}
	
	public TextView(TextModel model) {
		super(model);
		paragraphs = new ParagraphVector();
	}
	
	public TextModel getModel() {
		return (TextModel)super.getModel();
	}
	
	public void paint(Graphics g) {
		g.clear();
		
		TextSetter textSetter = new TextSetter(getScene(), null, getWidth());
		
		for(int i = 0; i < paragraphs.size(); i++)
			paragraphs.elementAt(i).paint(textSetter);
		textSetter.flush();
	}
}
